﻿using System;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 控件 MutiLabel 属性的XML转换
    /// </summary>
    public class MutiLabelPropertyXML : CtrlUIPropertyXML
    {
        /// <summary>
        /// 控件 PanelCtl 属性的XML转换
        /// </summary>
        /// <param name="panelCtl"></param>
        public MutiLabelPropertyXML(MutiLabel mutiLbl)
            : base(mutiLbl)
        {
            _mutiLbl = mutiLbl;
        }

        private MutiLabel _mutiLbl = null;

        public override string ToXML()
        {
            return "<TextAlign>" + ((int)_mutiLbl.TextAlign).ToString() + "</TextAlign>" +
                       "<BackgroundImage>" + ConvertImageToString(_mutiLbl.BackgroundImage) + "</BackgroundImage>" +
                       "<BackgroundImageLayout>" + ((int)_mutiLbl.BackgroundImageLayout).ToString() + "</BackgroundImageLayout>" +
                       "<Base>" + base.ToXML() + "</Base>";
        }

        public override void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                foreach (System.Xml.XmlNode XN in xns)
                {
                    switch (XN.Name.ToLower())
                    {
                        case "textalign":
                            _mutiLbl.TextAlign = (System.Drawing.ContentAlignment)Convert.ToInt32(XN.InnerText);
                            break;

                        case "backgroundimage":
                            _mutiLbl.BackgroundImage = XN.InnerText.Length > 0 ? ConvertStringToImage(XN.InnerText) : null;
                            break;

                        case "backgroundimagelayout":
                            _mutiLbl.BackgroundImageLayout = (System.Windows.Forms.ImageLayout)Convert.ToInt32(XN.InnerText);
                            break;

                        case "base":
                            base.FromXML(XN.ChildNodes);
                            break;

                        default:
                            break;
                    }
                }
            }
        }//
    }
}